home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / KEYBOARD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-19  |  3.7 KB  |  157 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <MINTBIND.H>
  9. #include <OSBIND.H>
  10. #include <FILESYS.H>
  11. #include <MINTBIND.H>
  12. #include "XA_DEFS.H"
  13. #include "XA_TYPES.H"
  14. #include "XA_GLOBL.H"
  15. #include "APP_MAN.H"
  16. #include "C_WINDOW.H"
  17. #include "EVNT_MUL.H"
  18. #include "TASKMAN.H"
  19. #include "FSELECT.H"
  20.  
  21. /*
  22.     Keyboard input handler
  23. */
  24.  
  25. void do_keyboard(void)
  26. {
  27.     long key;
  28.     unsigned short AESkey;
  29.     short shift_state;
  30.     XA_WINDOW *w=NULL;
  31.     XA_CLIENT *client;
  32.     short client_id;
  33.     short mx,my,mb,kstate;
  34.     unsigned long retv=XA_OK;
  35.     
  36.     vq_mouse(V_handle, &mb,&mx,&my);
  37.  
  38.     vq_key_s(V_handle,&shift_state);
  39.     kstate=shift_state;
  40.     
  41. #if ALT_CTRL_APP_OPS
  42. /* Check for control+alt+tab, and do an app swap if valid.... */
  43.     shift_state&=12;
  44.     if (shift_state==12)
  45.     {
  46.         key=Crawcin();
  47.         AESkey=(short)((key&0xff)|((key>>8)&0xff00));    /* translate the GEMDOS raw data into AES format*/
  48.  
  49.         switch(AESkey)
  50.         {
  51.             case 0xf09:            /* CTRL+ALT+TAB switches menu bars */
  52.                 next_app_menu();
  53.                 return;
  54.                 break;
  55.             case 0x1312:        /* Attempt to recover a hung system */
  56.                 recover();
  57.                 return;
  58.                 break;
  59.             case 0x2106:        /* Test the file selector */
  60.                 open_fileselector("u:\\","FS Tester",NULL,NULL);
  61.                 return;
  62.                 break;
  63.             case 0x260c:        /* Output a list of current clients via DIAGS */
  64. #if 0
  65.                 list_apps();
  66. #else
  67.                 open_taskmanager();
  68. #endif
  69.                 return;
  70.                 break;
  71.             case 0x250b:        /* Tidy up after any clients that have died without calling appl_exit() */
  72.                 find_dead_clients();
  73.                 return;
  74.                 break;
  75.             case 0x2004:        /* Dump the current system status */
  76.                 status_dump();
  77.                 return;
  78.                 break;
  79.         }
  80.     }
  81. #endif
  82.  
  83.     
  84. #if POINT_TO_TYPE
  85. /* Keyboard input goes to the application whose window is under the mouse */
  86.     w=wind_find(mx,my); 
  87.  
  88. /* If there is no window under the mouse, send to the top window instead */
  89.     if (!w)
  90.     {
  91.         w=window_list;
  92.     }else{
  93.         
  94.         if (!(w->owner->waiting_for&XAWAIT_KEY))    /* If window under mouse isn't waiting for keys, maybe the top window is? */
  95.             w=window_list;
  96.     }
  97. #else
  98.  
  99. /* Keyboard input always goes to the application whose window is on top */
  100.     w=window_list;
  101.     client_id=w->owner;
  102.     
  103. #endif
  104.  
  105.     if (update_lock)
  106.     {
  107.         client_id=update_lock;
  108.     }
  109.  
  110.     client=Pid2Client(client_id);
  111.  
  112.     if (!client)
  113.         return;
  114.  
  115.     DIAGS(("keyhandler:client_id=%d, window_owner=%d\n",client_id,w->owner));
  116.  
  117.     if ((w)&&(w->owner==client_id))
  118.     {
  119.         if (w->keypress)    /* Does the target window have a keypress handler callback? */
  120.         {
  121.             key=Crawcin();
  122.             AESkey=(short)((key&0xff)|((key>>8)&0xff00));    /* translate the GEMDOS raw data into AES format*/
  123.             (*(w->keypress))(w,AESkey);
  124.             return;
  125.         }
  126.     }
  127.  
  128.     Psemaphore(2,CLIENTS_SEMAPHORE,-1L);
  129.  
  130.     if (client->waiting_for&XAWAIT_KEY)    /* If the client owning the window was waiting for a keyboard event, send it */
  131.     {
  132.         key=Crawcin();
  133.         AESkey=(short)((key&0xff)|((key>>8)&0xff00));    /* translate the GEMDOS raw data into AES format*/
  134.  
  135.         if (client->waiting_for&XAWAIT_MULTI)    /* If the client is waiting on a multi, the response is  */
  136.         {                                                /* slightly different to the evnt_keybd() response. */
  137.             client->waiting_pb->intout[0]=MU_KEYBD;
  138.             client->waiting_pb->intout[1]=mx;
  139.             client->waiting_pb->intout[2]=my;
  140.             client->waiting_pb->intout[3]=mb;
  141.             client->waiting_pb->intout[4]=kstate;
  142.             client->waiting_pb->intout[5]=AESkey;
  143.             client->waiting_pb->intout[6]=0;
  144.             cancel_evnt_multi(client_id);
  145.         }else{
  146.             client->waiting_pb->intout[0]=AESkey;
  147.             client->waiting_for=0;    /* Now client isn't waiting for anything */
  148.         }
  149.         
  150.         Fwrite(client->clnt_pipe_wr,sizeof(unsigned long),&retv);    /* Write success to clients reply pipe to unblock the process */
  151.         
  152.     }
  153.         
  154.     Psemaphore(3,CLIENTS_SEMAPHORE,0L);
  155.  
  156. }
  157.